﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Argument.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Windows.Input
{
    using System;
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Markup;
    using ComponentModel;

    /// <summary>
    /// Represents an argument
    /// </summary>
    [ContentProperty("Value")]
    public class Argument : ArgumentBase
    {
        /// <summary>
        /// Identifies the <see cref="Value"/> dependency property.
        /// </summary>
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", 
            typeof(object), typeof(Argument), new PropertyMetadata(ValuePropertyChanged));

        /// <summary>
        /// Gets or sets the argument value.
        /// </summary>
        /// <value>The argument value.</value>
        [Category("Common Properties"), TypeConverter(typeof(StringObjectConverter))]
        public object Value
        {
            get { return GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }

        /// <summary>
        /// Evaluates the argument in the specified <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The context used to evaluate the argument.</param>
        /// <returns>The value of the argument.</returns>
        /// <remarks>When invoked via <see cref="TriggerBase"/> the context argument is the context of the tigger, for example when working with event triggers the context
        /// is the <see cref="EventArgs"/> of the event that raised the trigger.</remarks>
        protected override object Evaluate(object context)
        {
            return Value;
        }

        private static void ValuePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ((Argument)obj).RaiseRequerySuggested();
        }

#if !SILVERLIGHT
        protected override Freezable CreateInstanceCore()
        {
            return new Argument();
        }
#endif
    }
}